package com.czk.classreader.field;


import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/8/6 15:20
 */
public class ClassRemoveFieldVisitor extends ClassVisitor {
    private final String fieldName;
    private final String fieldDesc;

    public ClassRemoveFieldVisitor(int i, ClassVisitor classVisitor, String fieldName, String fieldDesc) {
        super(i, classVisitor);
        this.fieldName = fieldName;
        this.fieldDesc = fieldDesc;
    }

    @Override
    public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
        if (name.equals(fieldName)&&descriptor.equals(fieldDesc)){
            // 字段名字和描述符都相等
            // 返回null会打到删除字段的效果
            return null;
        }
        return super.visitField(access,name,descriptor,signature,value);
    }
}
